<?php
$this->load->view('includes/header');
$this->load->view('includes/nav');
$article = 0;
$article1 = array();
$article2 = array();
foreach ($videos as $key => $value) {
    if ($article == 0) {
        array_push($article1, $value);
        $article++;
    } else if ($article == 1) {
        array_push($article2, $value);
        $article = 0;
    }
}
?>
<script src="<?php echo base_url(); ?>public/js/libs/mustache.js"></script>
<script src="<?php echo base_url(); ?>public/js/lp_videos.js"></script>
<script src="<?php echo base_url(); ?>public/js/headerScrollFix.js"></script>

<section id="LeapMainWrapper">
    <div class="feedNavigation">
        <ul>
            <li id="popular" <?php if(isset ($_GET['cat']) && $_GET['cat']==='popular') echo 'class="selected"'; elseif(!isset ($_GET['cat'])) echo 'class="selected"';?>>
                        <a href="http://leapdemo.com/videos?cat=popular">Popular</a>
                    </li>
                    <li id="choice" <?php if(isset ($_GET['cat']) && $_GET['cat']==='choice') echo 'class="selected"'; ?>>
                        <a href="http://leapdemo.com/videos?cat=choice">Our Choice</a>
                    </li>
                    <li id="fresh" <?php if(isset ($_GET['cat']) && $_GET['cat']==='fresh') echo 'class="selected"'; ?>>
                        <a href="http://leapdemo.com/videos?cat=fresh">Fresh</a>
                    </li>
                    <li id="upcoming" <?php if(isset ($_GET['cat']) && $_GET['cat']==='upcoming') echo 'class="selected"'; ?>>
                        <a href="http://leapdemo.com/videos?cat=upcoming">Upcoming</a>
                    </li>
                    <li id="favorites" <?php if(isset ($_GET['cat']) && $_GET['cat']==='favorite') echo 'class="selected"'; ?>>
                        <a href="http://leapdemo.com/videos?cat=favorite">Favorites</a>
                    </li>
                </ul>
            </div>
    <section id="LeapContentWrapper">

        <section class="videoStream">
<?php foreach ($article1 as $key => $value) { ?>
                <div class="videohead" >
                    <div class="userInfos" id="<?php echo $value["video_infos"]['user']['user_id'] ?>">
                        <div class="videoInfos">
                            <div class="profileP">
                                <img src="<?php echo $value["video_infos"]['user']['profile_pic'] ?>" alt="<?php echo $value["video_infos"]['user']['first_name'] . " " . $value["video_infos"]['user']['last_name'] ?>" width="50px"/>
                                <p class="name"><a href="/<?php echo $value["video_infos"]['user']['username'] ?>"><?php echo $value["video_infos"]['user']['first_name'] . " " . $value["video_infos"]['user']['last_name'] ?></a></p>
                                <p class="addedtime"><?php echo isset($value['uploaded']) ? $value['uploaded'] : ""; ?></p>
                            </div>
                        </div>
                        <?php if($value["video_infos"]['connected']){ if($value["video_infos"]['user']['user_id'] !== $user_id){ ?>
                        <span class="button <?php if ($value["video_infos"]['isFollowing'])
                echo "fl"; else
                echo "follow"; ?>"><?php if ($value["video_infos"]['isFollowing'])
                echo "Unfollow"; else
                echo "Follow"; ?>
                        </span>
                        <?php }} ?>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <article class="videos">
                    <div class="mediaHolder">
                        <a class="videoPost" id="<?php echo $value['video_id']; ?>" href="/<?php echo $value['video_id']; ?>">
                            <img class="imgThumbPost <?php echo $value['identifier']; ?>" alt="<?php echo $value['title']; ?>" src="<?php echo $value['thumb']; ?>">
                            <i></i>
                            <?php
                            if (isset($value['hd']) && $value['hd'])
                                echo '<span class="hd"></span>';
                            ?>
                        </a>
                    </div>
                    <h4 class="title"><a href="videos/<?php echo $value['video_id']; ?>"><?php echo $value['title']; ?></a></h4>
                    <p class="description"><?php echo $value['description']; ?></p>
        <!--            <p class="uploadDate"><?php echo isset($value['uploaded']) ? $value['uploaded'] : ""; ?></p>-->
                    <div class="extendWrapper">
                        <div class="extendAction">
                            <ul id="<?php echo $value["video_infos"]['video']['video_id']; ?>">
                                <li class="VinfoList">
                                    <div class="commentsCount" >
                                     <span><?php echo count($value["video_infos"]['comments']); ?> comments</span>           
                                    </div>
                                </li>
                                <li class="VinfoList">

                                    <?php
                                    if ($value["video_infos"]['connected']) {
                                        echo '<div id="likeVideo" ';
                                    }else{
                                        echo '<div '; 
                                     }
                                    if ($value["video_infos"]['did_like'] && $value["video_infos"]['connected'])
                                        echo 'class="likeCount_f">';
                                    else
                                        echo 'class="likeCount">';
                                    echo $value["video_infos"]['likes'];
                                    echo "</div>";
                                    ?>          

                                </li>
                                <li class="VinfoList">
                                    <?php
                                     if ($value["video_infos"]['connected']) { 
                                        echo '<div id="FavVideo" ';
                                     }else{
                                        echo '<div '; 
                                     }
                                    
                                    if ($value["video_infos"]['did_fav'] && $value["video_infos"]['connected'])
                                        echo 'class="FavCount_f">';
                                    else
                                        echo 'class="FavCount">';
                                    echo $value["video_infos"]['favs'];
                                    echo "</div>";
                                    ?> 
                                </li>
                                <li class="VinfoList shareTo">
                                    <div class="shareMedia">
                                        
                                    </div>
                                </li>
                            </ul>
                        </div>
                        <div class="clearfix"></div>
                        <div class="extendVideo" id="<?php echo $value["video_infos"]['video']['video_id']; ?>">
                            <div class="commentsWrapper">
    <?php if ($value["video_infos"]['connected']) { ?>
                                    <div class="videocomment">
                                        <div class="commentProfilePic">

                                            <span class="profilePicVideo" ><img src="<?php echo $profile_pic_thumb; ?>" width="30" height="30" /></span>
                                        </div>
                                        <div class="videoCommentBody">
                                            <textarea class="comment" placeholder="Add comment..."></textarea>
                                        </div>
                                        <div class="clearfix"></div>
                                    </div>
                                        <?php } ?>
                                <div class="commentstream">
                                    <ul>
                                        <?php foreach ($value["video_infos"]['comments'] as $k => $val) { ?>
                                            <li>
                                                <span class="profilePicVideo" ><img src="<?php echo $val['user_profile_pic_thumb']; ?>" width="30" height="30" /></span>
                                                <div class="commentInfos">
                                                    <p class="user_name"><a href="<?php echo $val['user_name']; ?>"><?php echo $val['user_name']; ?></a></p>
                                                    <p class="added"><?php echo $val['timestamp']; ?></p>
                                                </div>
                                                <p class="comment_"><?php echo $val['comment']; ?></p>
                                                <div class="clearfix">
                                                </div>
                                            </li>
    <?php } ?>
                                    </ul>
                                </div>

                            </div>
                        </div>
                    </div>
                    <a class="moreVideoInfos" id="<?php echo $value['video_id']; ?>" href="<?php echo $value['video_id']; ?>">show more</a>
                    <div class="clearfix"></div>
                </article>
            <?php } ?>
        </section>
        <section class="videoStream">
<?php foreach ($article2 as $key => $value) { ?>
                <div class="videohead" >
                    <div class="userInfos" id="<?php echo $value["video_infos"]['user']['user_id'] ?>">
                        <div class="videoInfos">
                            <div class="profileP">
                                <img src="<?php echo $value["video_infos"]['user']['profile_pic'] ?>" alt="<?php echo $value["video_infos"]['user']['first_name'] . " " . $value["video_infos"]['user']['last_name'] ?>" width="50px"/>
                                <p class="name"><a href="/<?php echo $value["video_infos"]['user']['username'] ?>"><?php echo $value["video_infos"]['user']['first_name'] . " " . $value["video_infos"]['user']['last_name'] ?></a></p>
                                <p class="addedtime"><?php echo isset($value['uploaded']) ? $value['uploaded'] : ""; ?></p>
                            </div>
                        </div>
                        <?php if($value["video_infos"]['connected']){ if($value["video_infos"]['user']['user_id'] !== $user_id){ ?>
                        <span class="button <?php if ($value["video_infos"]['isFollowing'])
                echo "fl"; else
                echo "follow"; ?>"><?php if ($value["video_infos"]['isFollowing'])
                echo "Unfollow"; else
                echo "Follow"; ?>
                        </span>
                        <?php }} ?>
                        <div class="clearfix"></div>
                    </div>
                </div>
                <article class="videos">
                    <div class="mediaHolder">
                        <a class="videoPost" id="<?php echo $value['video_id']; ?>" href="/<?php echo $value['video_id']; ?>">
                            <img class="imgThumbPost <?php echo $value['identifier']; ?>" alt="<?php echo $value['title']; ?>" src="<?php echo $value['thumb']; ?>">
                            <i></i>
    <?php
    if (isset($value['hd']) && $value['hd'])
        echo '<span class="hd"></span>';
    ?>
                        </a>
                    </div>
                    <h4 class="title"><a href="videos/<?php echo $value['video_id']; ?>"><?php echo $value['title']; ?></a></h4>
                    <p class="description"><?php echo $value['description']; ?></p>
        <!--            <p class="uploadDate"><?php echo isset($value['uploaded']) ? $value['uploaded'] : ""; ?></p>-->
                    <div class="extendWrapper">
                        <div class="extendAction">
                            <ul id="<?php echo $value["video_infos"]['video']['video_id']; ?>">
                                <li class="VinfoList">
                                    <div class="commentsCount" >
                                    <span><?php echo count($value["video_infos"]['comments']); ?> comments</span>           
                                    </div>
                                </li>
                                <li class="VinfoList">

                                    <?php
                                    if ($value["video_infos"]['connected']) {
                                        echo '<div id="likeVideo" ';
                                    }else{
                                        echo '<div '; 
                                     }
                                    if ($value["video_infos"]['did_like'] && $value["video_infos"]['connected'])
                                        echo 'class="likeCount_f">';
                                    else
                                        echo 'class="likeCount">';
                                    echo $value["video_infos"]['likes'];
                                    echo "</div>";
                                    ?>          

                                </li>
                                <li class="VinfoList">
                                    <?php
                                     if ($value["video_infos"]['connected']) { 
                                        echo '<div id="FavVideo" ';
                                     }else{
                                        echo '<div '; 
                                     }
                                    
                                    if ($value["video_infos"]['did_fav'] && $value["video_infos"]['connected'])
                                        echo 'class="FavCount_f">';
                                    else
                                        echo 'class="FavCount">';
                                    echo $value["video_infos"]['favs'];
                                    echo "</div>";
                                    ?> 
                                </li>
                                <li class="VinfoList shareTo">
                                    <div class="shareMedia">
                                        
                                    </div>
                                </li>
                            </ul>
                        </div>
                        <div class="clearfix"></div>
                        <div class="extendVideo" id="<?php echo $value["video_infos"]['video']['video_id']; ?>">
                            <div class="commentsWrapper">
    <?php if ($value["video_infos"]['connected']) { ?>
                                    <div class="videocomment">
                                        <div class="commentProfilePic">

                                            <span class="profilePicVideo" ><img src="<?php echo $profile_pic_thumb; ?>" width="30" height="30" /></span>
                                        </div>
                                        <div class="videoCommentBody">
                                            <textarea class="comment" placeholder="Add comment..."></textarea>
                                        </div>
                                        <div class="clearfix"></div>
                                    </div>
                                        <?php } ?>
                                <div class="commentstream">
                                    <ul>
                                        <?php foreach ($value["video_infos"]['comments'] as $k => $val) { ?>
                                            <li>
                                                <span class="profilePicVideo" ><img src="<?php echo $val['user_profile_pic_thumb']; ?>" width="30" height="30" /></span>
                                                <div class="commentInfos">
                                                    <p class="user_name"><a href="<?php echo $val['user_name']; ?>"><?php echo $val['user_name']; ?></a></p>
                                                    <p class="added"><?php echo $val['timestamp']; ?></p>
                                                </div>
                                                <p class="comment_"><?php echo $val['comment']; ?></p>
                                                <div class="clearfix">
                                                </div>
                                            </li>
    <?php } ?>
                                    </ul>
                                </div>

                            </div>
                        </div>
                    </div>
                    <a class="moreVideoInfos" id="<?php echo $value['video_id']; ?>" href="<?php echo $value['video_id']; ?>">show more</a>
                    <div class="clearfix"></div>
                </article>
<?php } ?>
        </section>
    </section>
<?php $this->load->view('includes/sidebar'); ?> 

</section>
<script id="videoExtend_template" type="text/template">
    <div class="extendAction">
        <ul id="{{video_id}}">
            <li class="VinfoList">
                <div class="commentsCount" >
                    <span>{{comments_count}}</span> Comments           
                </div>
            </li>
            <li class="VinfoList short">
                <div id="likeVideo" 
                     {{#did_like}} 
                     class="likeCount_f"> 
                     {{/did_like}}
                     {{^did_like}}
                     class="likeCount"> 
                     {{/did_like}}
                     {{likes}}             
            </div>
        </li>
        <li class="VinfoList short">
            <div id="FavVideo" 
                 {{#did_fav}} 
                 class="FavCount_f">
                 {{/did_fav}}
                 {{^did_fav}}
                 class="FavCount"> 
                 {{/did_fav}}
                 {{favorites}} 
        </div>
    </li>
</ul>
</div>
<div class="clearfix"></div>
<div class="extendVideo" id="{{video_id}}">
    <div class="commentsWrapper">
        {{#connect}}
        <div class="videocomment">
            <div class="commentProfilePic">

                <span class="profilePicVideo" ><img src="<?php echo $profile_pic; ?>" width="30" height="30" /></span>
            </div>
            <div class="videoCommentBody">
                <textarea class="comment" placeholder="Add comment..."></textarea>
            </div>
            <div class="clearfix"></div>
        </div>
        {{/connect}}
        <div class="commentstream">
            <ul>
                {{#comments}}
                <li>
                    <span class="profilePicVideo" ><img src="{{user_profile_pic}}" width="30" height="30" /></span>
                    <div class="commentInfos">
                        <p class="user_name"><a href="{{user_name}}">{{user_name}}</a></p>
                        <p class="added">{{timestamp}}</p>
                    </div>
                    <p class="comment_">{{comment}}</p>
                    <div class="clearfix">
                    </div>
                </li>
                {{/comments}}
            </ul>
        </div>

    </div>
</div>
</script>
<div class="overlay_light"></div>
<script>
    $.lp.init();
    $.lp.register();
</script>
<?php
$this->load->view('includes/footer');
?>